import {postReqLog,getReq} from "../http";

const BASE_COUNT = 'BASE _COUNT'
const ERROR_MSG = 'ERROR_MSG'

const initState={
   data:null,
   msg:null
}
// reducer
export function home(state=initState, action){
    switch(action.type){
        case BASE_COUNT:
            return {...state,data:action.payload}
        case ERROR_MSG:
            return {...state,msg:action.msg}
        default:
            return state
    }
}

function success(obj){
    return {type: BASE_COUNT, payload:obj}
}

function errorMsg(msg){
    return { msg, type:ERROR_MSG }
}


export function getCount(){
    return async dispatch=>{
        let res = await getReq('/api/base_count')
        if(res.data){
            dispatch(success(res.data))
        }else {
            dispatch(errorMsg(res.msg))
        }
    }
}







